// 通用的信息
const INFO_KEY = 'hm_shopping_info'
const HISTORY_KEY = 'goods_history'

// 获取缓存信息
export const getInfo = () => {
  const defaultInfo = { token: '', userId: '' }
  const storage = localStorage.getItem(INFO_KEY)
  return storage ? JSON.parse(storage) : defaultInfo
}

// 设置个人信息缓存
export const setInfo = (userInfo) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(userInfo))
}

// 清除个人信息缓存
export const removeInfo = () => {
  localStorage.removeItem(INFO_KEY)
}

// 获取历史数据
export const getHistory = () => {
  const history = localStorage.getItem(HISTORY_KEY)
  return history ? JSON.parse(history) : []
}

// 设置历史数据
export const setHistory = (history) => {
  if (history && history.length > 0) {
    localStorage.setItem(HISTORY_KEY, JSON.stringify(history))
  }
}
